home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / OLE2BOOK.ZIP / CHAP13.ZIP / PATRON / ICLISITE.CPP < prev    next >
C/C++ Source or Header  |  1993-07-19  |  6KB  |  292 lines

  1. /*
  2.  * ICLISITE.CPP
  3.  *
  4.  * Implementation of the IOleClientSite interface for Patron's tenants.
  5.  *
  6.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  7.  *
  8.  * Kraig Brockschmidt, Software Design Engineer
  9.  * Microsoft Systems Developer Relations
  10.  *
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #include "patron.h"
  17.  
  18.  
  19. /*
  20.  * CImpIOleClientSite::CImpIOleClientSite
  21.  * CImpIOleClientSite::~CImpIOleClientSite
  22.  *
  23.  * Parameters (Constructor):
  24.  *  pTenant         LPTENANT of the tenant we're in.
  25.  *  punkOuter       LPUNKNOWN to which we delegate.
  26.  */
  27.  
  28. CImpIOleClientSite::CImpIOleClientSite(LPTENANT pTenant, LPUNKNOWN punkOuter)
  29.     {
  30.     m_cRef=0;
  31.     m_pTen=pTenant;
  32.     m_punkOuter=punkOuter;
  33.     return;
  34.     }
  35.  
  36. CImpIOleClientSite::~CImpIOleClientSite(void)
  37.     {
  38.     return;
  39.     }
  40.  
  41.  
  42.  
  43.  
  44. /*
  45.  * CImpIOleClientSite::QueryInterface
  46.  * CImpIOleClientSite::AddRef
  47.  * CImpIOleClientSite::Release
  48.  *
  49.  * Purpose:
  50.  *  IUnknown members for CImpIOleClientSite object.
  51.  */
  52.  
  53. STDMETHODIMP CImpIOleClientSite::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  54.     {
  55.     return m_punkOuter->QueryInterface(riid, ppv);
  56.     }
  57.  
  58.  
  59. STDMETHODIMP_(ULONG) CImpIOleClientSite::AddRef(void)
  60.     {
  61.     ++m_cRef;
  62.     return m_punkOuter->AddRef();
  63.     }
  64.  
  65. STDMETHODIMP_(ULONG) CImpIOleClientSite::Release(void)
  66.     {
  67.     --m_cRef;
  68.     return m_punkOuter->Release();
  69.     }
  70.  
  71.  
  72.  
  73.  
  74. /*
  75.  * CImpIOleClientSite::SaveObject
  76.  *
  77.  * Purpose:
  78.  *  Requests that the container call OleSave for the object that lives
  79.  *  here.  Typically this happens on server shutdown.
  80.  *
  81.  * Parameters:
  82.  *  None
  83.  *
  84.  * Return Value:
  85.  *  HRESULT         Standard.
  86.  */
  87.  
  88. STDMETHODIMP CImpIOleClientSite::SaveObject(void)
  89.     {
  90.     //Since we're already set up with the tenant to save, this is trivial.
  91.     m_pTen->Update();
  92.     return NOERROR;
  93.     }
  94.  
  95.  
  96.  
  97.  
  98.  
  99. /*
  100.  * CImpIOleClientSite::GetMoniker
  101.  *
  102.  * Purpose:
  103.  *  Retrieves the moniker for the site in which this object lives,
  104.  *  either the moniker relative to the container or the full moniker.
  105.  *
  106.  * Parameters:
  107.  *  dwAssign        DWORD specifying that the object wants moniker
  108.  *                  assignment.  Yeah.  Right.  Got any bridges to sell?
  109.  *  dwWhich         DWORD identifying which moniker the object wants,
  110.  *                  either the container's moniker, the moniker relative
  111.  *                  to this client site, or the full moniker.
  112.  *
  113.  * Return Value:
  114.  *  HRESULT         Standard.
  115.  */
  116.  
  117. STDMETHODIMP CImpIOleClientSite::GetMoniker(DWORD dwAssign, DWORD dwWhich
  118.     , LPMONIKER FAR *ppmk)
  119.     {
  120.     //CHAPTER13MOD
  121.     *ppmk=NULL;
  122.  
  123.     switch (dwWhich)
  124.         {
  125.         case OLEWHICHMK_CONTAINER:
  126.             //This is just the file we're living in.
  127.             if (NULL!=m_pTen->m_pmkFile)
  128.                 *ppmk=m_pTen->m_pmkFile;
  129.  
  130.             break;
  131.  
  132.         case OLEWHICHMK_OBJREL:
  133.             //This is everything but the filename.
  134.             if (NULL!=m_pTen->m_pmk)
  135.                 *ppmk=m_pTen->m_pmk;
  136.  
  137.             break;
  138.  
  139.         case OLEWHICHMK_OBJFULL:
  140.             //Concatenate the file and relative monikers for this one.
  141.             if (NULL!=m_pTen->m_pmkFile && NULL!=m_pTen->m_pmk)
  142.                 CreateGenericComposite(m_pTen->m_pmkFile, m_pTen->m_pmk, ppmk);
  143.  
  144.             break;
  145.         }
  146.  
  147.     if (NULL==*ppmk)
  148.         return ResultFromScode(E_FAIL);
  149.  
  150.     (*ppmk)->AddRef();
  151.     return NOERROR;
  152.     //End CHAPTER13MOD
  153.     }
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160. /*
  161.  * CImpIOleClientSite::GetContainer
  162.  *
  163.  * Purpose:
  164.  *  Returns a pointer to the document's IOleContainer interface.
  165.  *
  166.  * Parameters:
  167.  *  ppContainer     LPOLECONTAINER FAR * in which to return the interface.
  168.  *
  169.  * Return Value:
  170.  *  HRESULT         Standard.
  171.  */
  172.  
  173. STDMETHODIMP CImpIOleClientSite::GetContainer(LPOLECONTAINER FAR* ppContainer)
  174.     {
  175.     //CHAPTER13MOD
  176.     LPPAGE  pPage;
  177.  
  178.     *ppContainer=NULL;
  179.  
  180.     /*
  181.      * Here we want to get the interface on the page we're in.
  182.      * The function we call in CPages does not AddRef the page, but
  183.      * QueryInterface does.
  184.      */
  185.     m_pTen->m_pPG->IPageGetFromID((DWORD)-1, &pPage, FALSE);
  186.  
  187.     if (NULL!=pPage)
  188.         {
  189.         return pPage->QueryInterface(IID_IOleItemContainer
  190.             , (LPLPVOID)ppContainer);
  191.         }
  192.  
  193.     return ResultFromScode(E_FAIL);
  194.     //End CHAPTER13MOD
  195.     }
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. /*
  203.  * CImpIOleClientSite::ShowObject
  204.  *
  205.  * Purpose:
  206.  *  Tells the container to bring the object fully into view as much
  207.  *  as possible, that is, scroll the document.
  208.  *
  209.  * Parameters:
  210.  *  None
  211.  *
  212.  * Return Value:
  213.  *  HRESULT         Standard.
  214.  */
  215.  
  216. STDMETHODIMP CImpIOleClientSite::ShowObject(void)
  217.     {
  218.     HWND        hWnd, hWndT;
  219.  
  220.     /*
  221.      * We let the tenant do this, since it can access the current
  222.      * scroll position as a friend of CPages whereas we cannot.
  223.      */
  224.     m_pTen->ShowYourself();
  225.  
  226.     //CHAPTER13MOD
  227.     //For linking to embedding, now is the time to show the main window.
  228.     hWndT=GetParent(m_pTen->m_hWnd);
  229.  
  230.     while (NULL!=hWndT)
  231.         {
  232.         hWnd=hWndT;
  233.         hWndT=GetParent(hWnd);
  234.         }
  235.  
  236.     ShowWindow(hWnd, SW_SHOWNORMAL);
  237.     //End CHAPTER13MOD
  238.     return NOERROR;
  239.     }
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246. /*
  247.  * CImpIOleClientSite::OnShowWindow
  248.  *
  249.  * Purpose:
  250.  *  Informs the container if the object is showing itself or
  251.  *  hiding itself.  This is done only in the opening mode and allows
  252.  *  the container to know when to shade or unshade the object.
  253.  *
  254.  * Parameters:
  255.  *  fShow           BOOL indiciating that the object is being shown
  256.  *                  (TRUE) or hidden (FALSE).
  257.  * Return Value:
  258.  *  HRESULT         Standard.
  259.  */
  260.  
  261. STDMETHODIMP CImpIOleClientSite::OnShowWindow(BOOL fShow)
  262.     {
  263.     //All we have to do is tell the tenant of the open state change.
  264.     m_pTen->ShowAsOpen(fShow);
  265.     return NOERROR;
  266.     }
  267.  
  268.  
  269.  
  270.  
  271.  
  272.  
  273. /*
  274.  * CImpIOleClientSite::RequestNewObjectLayout
  275.  *
  276.  * Purpose:
  277.  *  Called when the object needs more room in the container and applies
  278.  *  only to extended layout negotiation not supported in OLE 2.0.
  279.  *
  280.  * Parameters:
  281.  *  None
  282.  *
  283.  * Return Value:
  284.  *  HRESULT         Standard.
  285.  */
  286.  
  287. STDMETHODIMP CImpIOleClientSite::RequestNewObjectLayout(void)
  288.     {
  289.     //Nothing to do since this is not supported in OLE 2.0.
  290.     return ResultFromScode(E_NOTIMPL);
  291.     }
  292.